//
//  ActivityDetailMessageCell.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 16/9/2.
//  Copyright © 2016年 陈区. All rights reserved.
//

#import "ActivityDetailMessageCell.h"

@interface ActivityDetailMessageCell ()

@property (nonatomic, strong) UILabel* contentLabel;

@end


@implementation ActivityDetailMessageCell

+ (instancetype)cellWithTableView:(UITableView*)tableView
{
    ActivityDetailMessageCell* cell = [tableView dequeueReusableCellWithIdentifier:kActivityDetailMessageCellIdentifier];
    
    if (cell == nil) {
        
        cell = [[ActivityDetailMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kActivityDetailMessageCellIdentifier];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier
{
    
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setFrame:(CGRect)frame
{
    frame.size.width = [UIScreen mainScreen].bounds.size.width;
    [super setFrame:frame];
}

- (void)setupUI
{
    self.accessoryType = UITableViewCellAccessoryNone;
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    CGRect cellBounds =CGRectZero;
    UIImageView *linebg = [[UIImageView alloc] initWithFrame:cellBounds];
    linebg.tag = 1060;
    linebg.image = [UIImage imageWithContentsOfFile:SEGPicName(@"common_line610px.png")];
    [self.contentView addSubview:linebg];
    
    UILabel * lblName = [[UILabel alloc] initWithFrame:CGRectMake(20, 15, 200, 15)];
    lblName.font = [UIFont systemFontOfSize:FONT_LIST_AND_DETAIL_SIZE];
    lblName.textColor=kColor_2;
    lblName.backgroundColor = [UIColor clearColor];
    lblName.text=@"留言";
    lblName.tag=1062;
    [self.contentView addSubview:lblName];
    
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    self.contentLabel.font = [UIFont systemFontOfSize:FONT_LIST_AND_DETAIL_SIZE];
    self.contentLabel.backgroundColor = [UIColor clearColor];
    self.contentLabel.textColor=kColor_1;
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
    self.contentLabel.tag = 1061;
    [self.contentView addSubview:self.contentLabel];
}

- (void)setContent:(NSString *)content
{
    UIImageView *linebg= (UIImageView *)[self.contentView viewWithTag:1060];
    UILabel * nameLab = (UILabel *)[self.contentView viewWithTag:1061];
    UILabel * lblName = (UILabel *)[self.contentView viewWithTag:1062];
    
    CGSize  titleSize=[content sizeWithFont:[UIFont systemFontOfSize:FONT_LIST_AND_DETAIL_SIZE] constrainedToSize:CGSizeMake(200.0f,10000.0f) lineBreakMode:NSLineBreakByCharWrapping];
    if (titleSize.height==0) {
        lblName.hidden=YES;
        nameLab.frame = CGRectMake(100, 15, 200, titleSize.height);
        linebg.frame = CGRectMake(10, 0, CGRectGetWidth(self.bounds), 0.5);
    }else{
        lblName.hidden=NO;
        nameLab.frame = CGRectMake(100, 15, 200, titleSize.height);
        linebg.frame = CGRectMake(10, titleSize.height+30, CGRectGetWidth(self.bounds), 0.5);
    }
    nameLab.text = content;
}

@end
